using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace OnlineAnadolu
{
    public partial class Mesajlarim : System.Web.UI.Page
    {
        Database db = new Database();
        int a = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["usertype"] == "")
            {
                Response.Redirect("HataSayfasi.aspx");
            }
        }

        protected void bt_Gelen_Click(object sender, EventArgs e)
        {
            string sr = "Select sender as Gonderen,subject as Konu,message as Mesaj,tarih as Tarih from sendmessage where receiver=N'"+Session["username"].ToString()+"'and tip=1";
            DataTable dt = new DataTable();
            dt = db.select(sr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Session["a"] = "1";
        }

        protected void bt_Giden_Click(object sender, EventArgs e)
        {
            string sr = "Select receiver as Alici,subject as Konu,message as Mesaj,tarih as Tarih from sendmessage where sender=N'" + Session["username"].ToString() + "' and tip=2";
            DataTable dt = new DataTable();
            dt = db.select(sr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Session["a"] = "2";

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (Session["a"].ToString() =="1")
            {
                string sil2 = "Delete  From sendmessage where sender=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text + "' and subject=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[2].Text + "' and message=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text + "' and tarih='" + Convert.ToDateTime(GridView1.Rows[GridView1.SelectedIndex].Cells[4].Text).ToString("MM.dd.yyyy HH:mm:ss") + "' and tip=1";
                db.insert(sil2);
                GridView1.DataBind();
            }
            if (Session["a"].ToString() == "2")
            {
                string sil2 = "Delete  From sendmessage where receiver=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text + "' and subject=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[2].Text + "' and message=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text + "' and tarih='" + Convert.ToDateTime(GridView1.Rows[GridView1.SelectedIndex].Cells[4].Text).ToString("MM.dd.yyyy HH:mm:ss") + "' and tip=2";
                db.insert(sil2);
                GridView1.DataBind();

            }

        }
    }
}
